package com.tduck.cloud.system.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tduck.cloud.system.entity.SysDeptPostEntity;
import com.tduck.cloud.system.entity.SysUserEntity;
import com.tduck.cloud.system.mapper.SysDeptPostMapper;
import com.tduck.cloud.system.service.SysDeptPostService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 部门岗位关系Service业务层处理
 *
 * @author tduck-gen
 * @date 2022-06-06 16:25:10
 */
@Service
public class SysDeptPostServiceImpl extends ServiceImpl<SysDeptPostMapper, SysDeptPostEntity> implements SysDeptPostService {


    @Override
    public Page page(Page page, SysDeptPostEntity deptPost) {
        return baseMapper.selectDeptPostPage(page, deptPost);
    }

    @Override
    public List<Integer> getPostListByUserId(Long userId) {
        return baseMapper.selectPostListByUserId(userId);
    }

    @Override
    public List<Integer> getDeptPostListByUserId(Long userId) {
        return baseMapper.selectDeptPostListByUserId(userId);
    }

    @Override
    public SysUserEntity getDeptLeader(Long deptId) {
        // 如果存在多个主管，取第一个
        List<SysUserEntity> userEntityList = baseMapper.selectDeptLeader(deptId);
        return CollUtil.getFirst(userEntityList);
    }

    @Override
    public List<SysUserEntity> getPostUserList(List<Long> postIds) {
        return baseMapper.selectPostUserList(postIds);
    }
}
